﻿using UnityEngine;
using System.Collections;
using ZXing;
using ZXing.QrCode;
using UnityEngine.UI;

public class CreatQR : MonoBehaviour
{
    public RawImage image;
    public Texture2D encoded;
    public string Lastresult;
    void Start()
    {
        encoded = new Texture2D(256, 256);
    }
    private static Color32[] Encode(string textForEncoding, int width, int height)
    {
        var writer = new BarcodeWriter
        {
            Format = BarcodeFormat.QR_CODE,
            Options = new QrCodeEncodingOptions
            {
                Height = height,
                Width = width
            }
        };
        return writer.Write(textForEncoding);
    }
    void Update()
    {
        Lastresult = Input_id.iii; 

        var textForEncoding = Lastresult;
        if (textForEncoding != null)
        {
            var color32 = Encode(textForEncoding, encoded.width, encoded.height);
            image.texture = encoded;

            encoded.SetPixels32(color32);
            encoded.Apply();

        }
    }
    void OnGUI()
    {
        //GUI.DrawTexture(new Rect(230, 190, 68,68), encoded);
    }
}